<template>
  <div class="app-container">
    <!-- 表格上方按钮 -->
    <div>
      <div style="float: left">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          >新增</el-button
        >
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleDelete"
          >批量移除</el-button
        >
        <el-button
          type="success"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          >班级学员批量导入</el-button
        >
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >班级学员批量导出</el-button
        >
        <el-tag type="success">班级学员总人数：{{ total }}</el-tag>
      </div>
      <right-toolbar
        @queryTable="getList"
        :columns="columns"
        style="float: right"
      ></right-toolbar>
    </div>
    <!-- 表格数据 -->
    <el-table
      border
      v-loading="loading"
      :data="studentList"
      @selection-change="handleSelectionChange"
      height="88vh"
      :header-cell-style="{ background: '#FAFAFA' }"
    >
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column
        type="index"
        width="50"
        align="center"
        header-align="center"
        label="序号"
      />
      <el-table-column label="学号" prop="id" v-if="columns[0].visible" />
      <el-table-column label="姓名" prop="username" v-if="columns[1].visible" />
      <el-table-column label="证件号码" prop="idcard" v-if="columns[2].visible">
        <template slot-scope="scope">{{
          scope.row.idcard ? scope.row.idcard : "---"
        }}</template>
      </el-table-column>
      <el-table-column label="手机号码" prop="mobile" v-if="columns[3].visible">
        <template slot-scope="scope">{{
          scope.row.mobile ? scope.row.mobile : "---"
        }}</template>
      </el-table-column>
      <el-table-column label="性别" prop="sex" v-if="columns[4].visible">
        <template slot-scope="scope">
          <span>{{
            scope.row.sex === 1 ? "女" : scope.row.sex === 2 ? "男" : "---"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" prop="age" v-if="columns[5].visible">
        <template slot-scope="scope">{{
          scope.row.age ? scope.row.age : "---"
        }}</template>
      </el-table-column>
      <el-table-column label="班级名称" prop="classname" v-if="columns[6].visible">
        <template slot-scope="scope">{{
          scope.row.classname ? scope.row.classname : "---"
        }}</template></el-table-column
      >
      <el-table-column label="职级" prop="grade" v-if="columns[14].visible">
        <template slot-scope="scope">{{
          scope.row.grade ? scope.row.grade : "---"
        }}</template></el-table-column
      >
      <el-table-column label="工种" prop="subjectname" v-if="columns[7].visible">
        <template slot-scope="scope">{{
          scope.row.subjectname ? scope.row.subjectname : "---"
        }}</template></el-table-column
      >
      <el-table-column label="已学时长(分钟)" prop="learnTime" v-if="columns[8].visible">
        // 若learn_time为空,则显示“未开始”
        <template slot-scope="scope">
          <span v-if="scope.row.learnTime">{{ scope.row.learnTime }}</span>
          <span v-else>未开始</span>
        </template>
      </el-table-column>
      <el-table-column
        label="课程学习进度(%)"
        prop="progress"
        v-if="columns[9].visible"
      ></el-table-column>
      <el-table-column label="是否完成学习" prop="is_pass" v-if="columns[10].visible">
        <template slot-scope="scope">
          <span v-if="scope.row.progress == 100" style="color: green">已完成</span>
          <span v-else style="color: rgb(231, 231, 87)">未完成</span>
        </template>
      </el-table-column>
      <el-table-column label="学员状态" prop="stateName" v-if="columns[11].visible">
        <template slot-scope="scope">{{
          scope.row.stateName ? scope.row.stateName : "---"
        }}</template></el-table-column
      >
      <el-table-column label="备注" prop="user.remark" v-if="columns[12].visible">
        <template slot-scope="scope">{{
          scope.row.remark ? scope.row.remark : "无"
        }}</template></el-table-column
      >
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        v-if="columns[13].visible"
      >
        <template slot-scope="scope" v-if="scope.row.userId !== 1">
          <!-- <el-button size="medium" type="text" @click="handleUpdate(scope.row)"
            >编辑</el-button
          > -->
          <el-button size="medium" type="text" @click="handleDelete(scope.row)"
            >移除</el-button
          >
          <el-button size="medium" type="text" @click="giveCertificate(scope.row)"
            >颁发证书</el-button
          >
          <el-button size="medium" type="text" @click="viewCertificates(scope.row)"
            >查看证书</el-button
          >
          <el-button size="medium" type="text" @click="viewVideoRecord(scope.row)"
            >视频学习记录</el-button
          >
          <el-button size="medium" type="text" @click="viewQuestionRecord(scope.row)"
            >做题记录</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 新增用户信息 -->
    <el-dialog title="新增班级学员" :visible.sync="addDialog" width="60%">
      <!--搜索框-->
      <el-form :model="addQueryParams" size="small" :inline="true" label-width="70px">
        <el-form-item label="学号" prop="studentId">
          <el-input
            v-model="addQueryParams.id"
            placeholder="请输入学员学号"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="姓名" prop="studentName">
          <el-input
            v-model="addQueryParams.username"
            placeholder="请输入学员姓名"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="身份证号" prop="studentName">
          <el-input
            v-model="addQueryParams.idcard"
            placeholder="请输入学员身份证"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="手机号码" prop="phonenumber">
          <el-input
            v-model="addQueryParams.mobile"
            placeholder="请输入手机号码"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getAddList"
            >搜索</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="resetAddList"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        border
        v-loading="loading"
        :data="addQueryList"
        @selection-change="handleSelectionChange"
        :header-cell-style="{ background: '#FAFAFA' }"
        class="addDialog"
      >
        <el-table-column type="selection" width="50" align="center" />
        <!-- <el-table-column
          label="学员id"
          prop="id"
          :show-overflow-tooltip="true"
        /> -->
        <el-table-column label="学号" prop="id" :show-overflow-tooltip="true" />
        <el-table-column label="姓名" prop="username" :show-overflow-tooltip="true" />
        <el-table-column label="身份证号" prop="idcard" :show-overflow-tooltip="false" />
        <el-table-column label="手机号码" prop="mobile" :show-overflow-tooltip="true" />
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialog = false">取 消</el-button>
        <el-button type="primary" @click="submitAdd">添加选中学员</el-button>
      </span>
    </el-dialog>
    <!-- 修改用户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="身份证号" prop="idcard">
              <el-input
                v-model="form.idcard"
                placeholder="请输入学员身份证号"
                maxlength="30"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="mobile">
              <el-input
                v-model="form.mobile"
                placeholder="请输入学员手机号码"
                maxlength="11"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="username">
              <el-input
                v-model="form.username"
                placeholder="请输入学员姓名"
                maxlength="30"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年龄" prop="age">
              <el-input-number
                v-model="form.age"
                :min="1"
                :max="150"
                label="年龄"
              ></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="昵称" prop="nickname">
              <el-input
                v-model="form.nickname"
                placeholder="请输入学员昵称"
                prop="nickname"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-radio-group v-model="form.sex">
                <el-radio :label="2">男</el-radio>
                <el-radio :label="1">女</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 查看学习时长 -->
    <el-dialog title="学员学习时长" :visible.sync="timeDialog" width="30%">
      <span>{{ Math.round(studyTime / 3600) }} 小时</span>
      <span>{{ Math.round((studyTime % 3600) / 60) }} 分钟</span>
      <span>{{ studyTime % 60 }}秒 </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="timeDialog = false">取 消</el-button>
        <el-button type="primary" @click="timeDialog = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 颁发证书 -->
    <el-dialog title="颁发证书" :visible.sync="certificateDialog" width="30%">
      <el-form :model="certificateForm" label-width="80px">
        <!-- 上传证书图片 -->
        <el-form-item label="证书图片" prop="cover">
          <el-upload
            class="upload-demo"
            :action="uploadURL"
            :on-remove="handleRemove"
            :on-success="handleSuccess"
            list-type="picture"
            :limit="1"
            accept=".jpg, .jpeg, .png, .JPG, .JPEG"
            :auto-upload="true"
          >
            <el-button size="small" type="primary">点击选取</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/jpeg/png文件</div>
          </el-upload>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="certificateDialog = false">取 消</el-button>
        <el-button type="primary" @click="submitCertificate()">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog
      :title="upload2.title"
      :visible.sync="upload2.open"
      width="400px"
      append-to-body
    >
      <span>
        在此导入的学员将直接加入该班级
        <br />导入后，系统将自动生成学员的登录账户
        <br />账号：身份证号或手机号，初始密码：123456</span
      >
      <!-- 
        下方的:headers="upload.headers"是为了解决跨域问题，如果不需要跨域，可以去掉
      -->
      <el-upload
        ref="upload2"
        :limit="1"
        accept=".xlsx, .xls"
        :action="upload2.url"
        :disabled="upload2.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :on-exceed="handleFileExceed"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link
            type="primary"
            :underline="false"
            style="font-size: 12px; vertical-align: baseline"
            href="https://school-file-mjzx.oss-cn-guangzhou.aliyuncs.com/ExcelTemplate/batchImportStudentsTemplate.xlsx"
            >下载模板</el-link
          >
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload2.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getUnClassStudentList,
  updateInfo,
  getStudyTime,
  getIllegalStudent,
} from "@/api/student";
import { getClassStudent, updateClassMember } from "@/api/class/classStudent";
import { mapGetters } from "vuex";
import { issueCertificate } from "@/api/certificate";
import * as XLSX from "xlsx";
import { Message } from "element-ui";
export default {
  name: "classStudent",
  computed: {
    ...mapGetters(["companyId"]),
  },
  components: {},
  data() {
    return {
      //班级id
      classId: this.$route.query.id,
      //工种id
      subjectId: this.$route.query.subjectId,
      // 职级
      grade: this.$route.query.grade,
      // 表格加载遮罩层
      loading: false,
      // 选中数组
      ids: [],
      status: 0,
      // 批量删除时非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总记录数
      total: 1,
      // 学生用户表格数据
      studentList: null,
      //新增学生列表查询
      addQueryList: null,
      //班级学生列表查询
      addQueryParams: {
        id: null,
        username: null,
        idcard: null,
        mobile: null,
      },
      //证书对话框
      certificateDialog: false,
      //评价表单
      certificateForm: {
        courseVideoId: this.$route.query.courseVideoId,
        gradeId: this.$route.query.gradeId,
        studentId: "",
        cover: "",
      },
      //查看学习时长对话框
      timeDialog: false,
      //学习时长
      studyTime: 0,
      // 修改对话框标题
      title: "",
      // 是否显示修改对话框
      open: false,
      //证书上传接口
      uploadURL: process.env.BASE_API + "/coursewareOss/uploadOssCoursewareCover",
      //添加对话框
      addDialog: false,
      //添加信息表单
      addForm: {},
      // 修改信息表单参数
      form: {},
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
      },
      // 查询参数
      queryParams: {
        page: 1,
        limit: 5,
        username: undefined,
        mobile: undefined,
        idcard: undefined,
      },
      // 展示的列信息
      columns: [
        { key: 0, label: `学号`, value: "id", visible: true },
        { key: 1, label: `姓名`, value: "username", visible: true },
        { key: 2, label: `证件号码`, value: "idcard", visible: true },
        { key: 3, label: `手机号码`, value: "mobile", visible: true },
        { key: 4, label: `性别`, value: "sex", visible: true },
        { key: 5, label: `年龄`, value: "age", visible: true },
        { key: 6, label: `班级名称`, value: "classname", visible: true },
        { key: 7, label: `工种`, value: "subjectname", visible: true },
        { key: 8, label: `已学时长`, value: "learnTime", visible: true },
        { key: 9, label: `课程学习进度`, value: "progress", visible: true },
        { key: 10, label: `是否完成学习`, value: "is_pass", visible: true },
        { key: 11, label: `状态`, value: "stateName", visible: true },
        { key: 12, label: `备注`, value: "remark", visible: true },
        { key: 13, label: `职级`, value: "grade", visible: true },
        { key: 14, label: `操作`, visible: true },
      ],
      // 修改表单校验
      rules: {
        // username: [
        //   { required: true, message: "学员姓名不能为空", trigger: "blur" },
        //   {
        //     min: 2,
        //     max: 20,
        //     message: "学员姓名长度必须介于 2 和 20 之间",
        //     trigger: "blur",
        //   },
        // ],
        // idcard: [
        //   { required: true, message: "身份证号不能为空", trigger: "blur" },
        // ],
      },
      // 课程学员批量导入参数
      // 用户导入参数
      upload2: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        // headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: "",
      },
      // 选中的学员
      selectedRows: [],
    };
  },
  watch: {},
  created() {
    this.getList();
    this.initUploadUrl();
  },
  methods: {
    // 初始化上传Excel的URL
    initUploadUrl() {
      this.upload2.url =
        process.env.BASE_API +
        "/eduM2/eduClass/batchImportClassStudent/" +
        this.companyId +
        "/" +
        this.classId +
        "/" +
        this.subjectId +
        "/" +
        this.grade;
      //console.log(this.upload2.url);
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      getClassStudent(this.classId).then((response) => {
        //console.log(response);
        this.studentList = response.data.resList;
        //console.log(this.studentList);
        this.total = response.data.total;
        this.loading = false;
      });
    },
    //添加学生查询
    getAddList() {
      getUnClassStudentList(this.companyId, this.addQueryParams)
        .then((response) => {
          this.addQueryList = response;
          console.log(this.addQueryList);
        })
    },
    //重置添加学生查询
    resetAddList() {
      this.addQueryParams = {
        id: null,
        username: null,
        idcard: null,
        mobile: null,
      };
      this.getAddList();
    },
    //重置查询表单
    reset() {
      this.addForm = {
        username: undefined,
        idcard: undefined,
        password: undefined,
        mobile: undefined,
      };
      this.resetForm("addForm");
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        page: 1,
        limit: 5,
        username: undefined,
        mobile: undefined,
        idcard: undefined,
      };
      this.getList();
    },
    // 表单重置
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
    // 多选框选中学员
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.selectedRows = selection;
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.addDialog = true;
      this.getAddList();
    },
    //提交修改
    submitAdd() {
      updateClassMember(1, this.classId, this.ids).then((response) => {
        this.$message({
          message: "添加成功",
          type: "success",
        });
        this.getList();
        this.addDialog = false;
        this.ids = [];
      });
    },
    // 查看学习时长
    viewTime(row) {
      getStudyTime(row.id).then((res) => {
        this.studyTime = res.data.totalCost;
        this.timeDialog = true;
      });
    },
    //查看视频学习记录
    viewVideoRecord(row) {
      this.$router.push({
        name: "VideoRecord",
        query: {
          id: row.id,
          studentName: row.username,
        },
      });
    },
    //查看做题学习记录
    viewQuestionRecord(row) {
      this.$router.push({
        name: "QuestionRecord",
        query: {
          id: row.id,
          studentName: row.username,
        },
      });
    },
    //查看证书
    viewCertificates(row) {
      this.$router.push({
        name: "StudentCertificate",
        query: {
          id: row.id,
        },
      });
    },
    //颁发证书
    giveCertificate(row) {
      this.certificateForm.studentId = row.id;
      this.certificateDialog = true;
    },
    //提交证书
    submitCertificate() {
      issueCertificate(this.certificateForm).then((res) => {
        if (res.success == true) {
          this.$message({
            message: "提交成功",
            type: "success",
          });
          this.certificateForm.cover = "";
          this.certificateDialog = false;
        } else {
          this.$message({
            message: "提交失败",
            type: "error",
          });
        }
      });
    },
    /** 修改信息按钮操作 */
    handleUpdate(row) {
      this.open = true;
      this.form = row;
    },
    /** 提交修改按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          updateInfo(this.form).then((response) => {
            this.open = false;
            this.$message({
              message: "修改成功",
              type: "success",
            });
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let id1 = [];
      id1.push(row.id);
      if(this.ids.length == 0){
        this.ids = id1;
      }
      //console.log('this.ids',this.ids)
      this.$confirm("是否确认退班学员？", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          updateClassMember(0, this.classId, this.ids).then((response) => {
            this.$message({
              message: "退班成功",
              type: "success",
            });
            this.getList();
            this.ids = [];
          });
        })
        .catch(() => {});
    },
    //筛选出不符合条件的学员
    getIllegalStudent() {
      getIllegalStudent(this.classId).then((res) => {
        //console.log(res);
        if (res.success == true) {
          this.$message({
            message: "筛选成功",
            type: "success",
          });
          this.getList();
        } else {
          this.$message({
            message: "筛选失败",
            type: "error",
          });
        }
      });
    },
    //handleSuccess
    handleSuccess(res, file) {
      this.certificateForm.cover = res.data.url;
    },
    //handleRemove
    handleRemove(file, fileList) {
      this.certificateForm.cover = "";
    },
    //跳转页面
    goto: function (current) {
      this.queryParams.page = current;
      this.getList();
    },
    //页码改变
    sizeChange: function (size) {
      this.queryParams.limit = size;
      this.getList();
    },

    // 批量上传操作
    /** 导入按钮操作 */
    handleImport() {
      this.upload2.title = "批量导入学员";
      this.upload2.open = true;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload2.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload2.open = false;
      this.upload2.isUploading = false;
      this.$refs.upload2.clearFiles();
      this.$message({
        message: "导入成功",
        type: "success",
      });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload2.submit();
    },
    // 文件上传超出个数限制处理
    handleFileExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 1 个文件，本次选择了 ${
          files.length + fileList.length
        } 个文件，共选择了 ${files.length} 个文件`
      );
    },

    // 学员批量导出操作
    handleExport() {
      if (this.selectedRows.length > 0) {
        this.$confirm(`是否确认导出选中的${this.selectedRows.length}个学员？`, {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            // 用户点击了确定按钮，执行导出操作
            // 创建英文字段名到中文字段名的映射表
            const fieldMap = {
              id: "学号",
              username: "姓名",
              idcard: "身份证号",
              mobile: "联系电话",
              sex: "性别",
              age: "年龄",
              classname: "班级名称",
              subjectname: "工种",
              learnTime: "已学时长(分钟)",
              progress: "课程学习进度(%)",
              is_pass: "是否完成学习",
              isDisabled: "是否禁用",
              stateName: "学员状态",
              remark: "备注",
              grade: "职级",
              // 其他字段...
            };
            // 将英文字段名转化为中文字段名
            //console.log(this.selectedRows);
            const data = this.selectedRows.map((row) => {
              const newRow = {};
              for (let key in row) {
                //如果key等于this.columns其中的value且this.columns中的visible为false,则使其跳出该层循环
                var flag = 0;
                for (let i = 0; i < this.columns.length; i++) {
                  if (key === this.columns[i].value && this.columns[i].visible == false) {
                    flag = 1;
                    break;
                  }
                }
                if (flag == 1) continue;
                //如果key等于avatar、classId、companyId、gmtCreate、gmtModified、nickname、openid、subjectId、password，则不导出
                if (
                  key === "avatar" ||
                  key === "classId" ||
                  key === "companyId" ||
                  key === "gmtCreate" ||
                  key === "gmtModified" ||
                  key === "nickname" ||
                  key === "openid" ||
                  key === "subjectId" ||
                  key === "password" ||
                  key === "grade" ||
                  key === "state" ||
                  key === "isDeleted" ||
                  key === "subjectParentId"
                ) {
                  continue;
                }
                if (fieldMap[key]) {
                  newRow[fieldMap[key]] = row[key];
                } else {
                  newRow[key] = row[key];
                }
              }
              return newRow;
            });
            //console.log(this.selectedRows);
            //console.log(data);
            const worksheet = XLSX.utils.json_to_sheet(data);
            const workbook = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(workbook, worksheet, "学员信息");
            XLSX.writeFile(workbook, "学员信息.xlsx");

            Message.success("导出成功");
          })
          .catch(() => {
            // 用户点击了取消按钮，不执行任何操作
          });
      } else {
        this.$message({
          type: "warning",
          message: "请先选择要导出的学员",
        });
      }
    },
  },
};
</script>

<style scoped>
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}

.el-icon-d-arrow-right {
  font-size: 12px;
}

.addDialog {
  height: 50vh;
  overflow: auto;
}
</style>
